package net.sxnic.workflow.context;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import net.sxnic.workflow.handler.WfHandlerException;
import net.sxnic.workflow.task.Task;
import net.sxnic.workflow.task.TaskComment;
import net.sxnic.workflow.task.TaskManager;
import net.sxnic.workflow.wfentity.WfEntityManager;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;

@Component("wfContext")
public class WfContextImpl<T> implements WfContext<T> {
	
	public WfContextImpl() {
		super();
		this.pros = new HashMap<String, Object>();
	}

	public static final String BUTTON_TYPE_SAVE = "保存";
	public static final String BUTTON_TYPE_SUBMIT = "签字发送";
	public static final String BUTTON_TYPE_GOBACK = "返回";
	public static final String BUTTON_TYPE_BACK = "退回";
	public static final String BUTTON_TYPE_ATTCHMENT_ADD = "上传";
	public static final String BUTTON_TYPE_COMMENT = "意见";
	public static final String BUTTON_TYPE_GUIDANG = "归档";
	public static final String BUTTON_TYPE_DELETE = "删除";
	
	protected String entityId;
	
	protected String taskId;

	protected TaskManager taskManager;

	protected Task task;

	protected WfEntityManager wfenManager;

	/**
	 * 错误信息
	 */
	protected String errorMsg;

	/**
	 * 任务名称，当前节点名称
	 */
	protected String taskName;

	/**
	 * 当前流程名
	 */
	protected String processName;

	/**
	 * 接收人在页面上的元素名。格式：承办-处长1,承办-处长2,批办-领导1
	 */
	protected String nextAssignee;

	/**
	 * 接收人HTML
	 */
	protected String nextAssigneesHtml;

	/**
	 * 可选接收人序列
	 */
	protected String nextAssignees;

	/**
	 * 选中接收人序列。格式：承办:处长1,处长2&批办:领导1,领导2
	 */
	protected String selectedNextAssignees;

	/**
	 * 页面点击按钮情况，一般为 保存 签字发送 返回 退回
	 */
	protected String buttonType;

	/**
	 * 签字密码
	 */
	protected String signPassword;

	protected File upload;

	protected String uploadFileName;
	
	protected Map<String,Object> pros;
	
	protected T entity;
	
	protected String taskComment;
	
	protected Map<String, Set<TaskComment>> commentMap;
	
	public void validateAbstract() throws WfHandlerException{
		if(taskManager ==null){
			throw new WfHandlerException("===context中===taskManager没有赋值===");
		}
		
		if(StringUtils.isBlank(processName)){
			throw new WfHandlerException("===context中===流程名没有赋值===");
		}
		
		if(StringUtils.isBlank(taskName)){
			throw new WfHandlerException("===context中===节点名没有赋值===");
		}
	}

	public WfContextImpl(TaskManager taskManager, Task task) {
		this.taskManager = taskManager;
		this.task = task;
	}

	public TaskManager getTaskManager() {
		return taskManager;
	}

	public void setTaskManager(TaskManager taskManager) {
		this.taskManager = taskManager;
	}

	public Task getTask() {
		return task;
	}

	public void setTask(Task task) {
		this.task = task;
	}


	public String getErrorMsg() {
		return errorMsg;
	}

	public void setErrorMsg(String errorMsg) {
		this.errorMsg = errorMsg;
	}

	public String getTaskName() {
		return taskName;
	}

	public void setTaskName(String taskName) {
		this.taskName = taskName;
	}

	public String getProcessName() {
		return processName;
	}

	public void setProcessName(String processName) {
		this.processName = processName;
	}

	public String getNextAssignee() {
		return nextAssignee;
	}

	public void setNextAssignee(String nextAssignee) {
		this.nextAssignee = nextAssignee;
	}

	public String getNextAssigneesHtml() {
		return nextAssigneesHtml;
	}

	public void setNextAssigneesHtml(String nextAssigneesHtml) {
		this.nextAssigneesHtml = nextAssigneesHtml;
	}

	public String getNextAssignees() {
		return nextAssignees;
	}

	public void setNextAssignees(String nextAssignees) {
		this.nextAssignees = nextAssignees;
	}

	public String getSelectedNextAssignees() {
		return selectedNextAssignees;
	}

	public void setSelectedNextAssignees(String selectedNextAssignees) {
		this.selectedNextAssignees = selectedNextAssignees;
	}

	public String getButtonType() {
		return buttonType;
	}

	public void setButtonType(String buttonType) {
		this.buttonType = buttonType;
	}

	public String getSignPassword() {
		return signPassword;
	}

	public void setSignPassword(String signPassword) {
		this.signPassword = signPassword;
	}

	public File getUpload() {
		return upload;
	}

	public void setUpload(File upload) {
		this.upload = upload;
	}

	public String getUploadFileName() {
		return uploadFileName;
	}

	public void setUploadFileName(String uploadFileName) {
		this.uploadFileName = uploadFileName;
	}

	public String getEntityId() {
		return entityId;
	}

	public void setEntityId(String entityId) {
		this.entityId = entityId;
	}

	public Map<String, Object> getPros() {
		return pros;
	}

	public void setPros(Map<String, Object> pros) {
		this.pros = pros;
	}

	public T getEntity() {
		return entity;
	}

	public void setEntity(T entity) {
		this.entity = entity;
	}

	@Override
	public void validateSelf() throws WfHandlerException {
		// TODO Auto-generated method stub
		
	}

	public String getTaskComment() {
		return taskComment;
	}

	public void setTaskComment(String taskComment) {
		this.taskComment = taskComment;
	}

	public WfEntityManager getWfenManager() {
		return wfenManager;
	}

	public void setWfenManager(WfEntityManager wfenManager) {
		this.wfenManager = wfenManager;
	}

	public String getTaskId() {
		return taskId;
	}

	public void setTaskId(String taskId) {
		this.taskId = taskId;
	}

	public Map<String, Set<TaskComment>> getCommentMap() {
		return commentMap;
	}

	public void setCommentMap(Map<String, Set<TaskComment>> commentMap) {
		this.commentMap = commentMap;
	}

}
